﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using TT.HelpInfo;
using SQLHelper;
using Bill.BasDLL.ety;
using System.Data;

namespace Bill.BasDLL.dao
{
    public class daoOraBillCode : basClassDeclare
    {
        public daoOraBillCode(TT.Module.sysLogin.etyBaeSystemParamter basSysPara)
        {
            _sqlHelp = basSysPara.SqlHelp;
            sPortCode = basSysPara.PORT_CODE;
            sUserID = basSysPara.UserID;
        }

        public bool Insert(etyBillCode eyTrk)
        {
            eyTrk.PORT_CODE = sPortCode;
            eyTrk.LST_USER = sUserID;
            string sql = "insert into bill_code (PORT_CODE,CASH_FLAG,ITEM,ITEM_UNIT,ITEM_GROUP,ITEM_DESC,LST_MOD,LST_USER,SUM_METER,IO_FLAG) "
                + "values(:PORT_CODE,:CASH_FLAG,:ITEM,:ITEM_UNIT,:ITEM_GROUP,:ITEM_DESC,:LST_MOD,:LST_USER,:SUM_METER,:IO_FLAG)";

            return _sqlHelp.ExecuteTrans(sql, eyTrk).Exec_Success;

        }

        public bool Update(etyBillCode eyTrk)
        {
            eyTrk.PORT_CODE = sPortCode;
            eyTrk.LST_USER = sUserID;
            string sql = "update bill_code set CASH_FLAG=:CASH_FLAG, item_unit=:item_unit,item_group=:item_group,item_desc=:item_desc,io_flag=:io_flag,lst_mod=:lst_mod,lst_user=:lst_user,lst_upd_date=sysdate"
                 + " where port_code=:port_code and item=:item";

            return _sqlHelp.ExecuteTrans(sql, eyTrk).Exec_Success;

        }

        public bool Delete(etyBillCode eyBillCode)
        {
            string sql = "delete from bill_code "
                + " where port_code=:port_code and item=:item";

            return _sqlHelp.ExecuteTrans(sql, eyBillCode).Exec_Success;

        }

        public DataTable GetBillCode()
        {
            string sql = string.Empty;
            sql = "select c.PORT_CODE,c.ITEM,c.ITEM_UNIT,c.ITEM_GROUP,c.ITEM_DESC,c.LST_MOD,c.LST_USER,c.SUM_METER,r.code_desc,C.IO_FLAG,c.CASH_FLAG "
                + " from bill_code c"
                + " INNER JOIN CODE_REF R ON c.item_unit=r.code and r.item='BILL_UNIT' "
                + " where port_code=:port_code";
            DataTable dt;
            dt = _sqlHelp.ExecuteReader(sql, new string[] { sPortCode });
            return dt;
        }
    }
}
